//
//  U9stockManager.m
//  U9WatchGame
//
//  Created by uuu9 on 2018/9/21.
//  Copyright © 2018年 UUU9. All rights reserved.
//

#import "U9stockManager.h"
#import "U9StockListModel.h"
#import "U9InvestMinModel.h"
#import "U9InvestStockModel.h"
#import "U9BonusModel.h"


@implementation U9stockManager

+ (void)getStockListWithUserid:(NSString *)uid andSessionid:(NSString *)sessionid andChannelID:(NSString *)cid andPageNum:(NSString *)pageNum andCompletionHandle:(void (^)(U9StockListModel *, NSError *))complete{
    PlistStorage *plist = [PlistStorage sharedPlistStorage];
     NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",uid,sessionid];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@?cid=%@&page=%@",Api_URL,kStockList,cid,pageNum]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
    U9StockListModel *model = [U9StockListModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
        model = [U9StockListModel mj_objectWithKeyValues:[plist readFromPlist:@"StocksList"]];
    } else if (error) {
        model = [U9StockListModel mj_objectWithKeyValues:[plist readFromPlist:@"StocksList"]];
    } else {
        [plist storageToPlist:responseObj andFileName:@"StocksList"];
    }
    complete(model,error);
}];
}


+ (void)getInvestMinWithClubID:(NSString *)cid andCompletionHandle:(void (^)(U9InvestMinModel *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@?cid=%@",Api_URL,kGetInvestMin,cid]
    parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9InvestMinModel *model = [U9InvestMinModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}


//参数 userid clubid（俱乐部id） score（投资积分值
+ (void)investStockWithUserid:(NSString *)uid andSessionid:(NSString *)sessionid andClubid:(NSString *)clubid andScore:(NSString *)score andCompletionHandle:(void (^)(U9InvestStockModel *, NSError *))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@&clubid=%@&score=%@",uid,sessionid,clubid,score];
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kInvest]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9InvestStockModel *model = [U9InvestStockModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}

+ (void)getUserBonusWithUserid:(NSString *)uid andSessionid:(NSString *)sessionid andCompletionHandle:(void (^)(U9BonusModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",uid,sessionid];
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetUserBonus]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9BonusModel *model = [U9BonusModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}

+(void)getExchangeRecordWithCompletionHandle:(void (^)(U9InvestMinModel *, NSError *))complete
{
    
}


+(void)cancelInvestWithClubID:(NSString *)cid andUserid:(NSString *)uid andSessionid:(NSString *)sessionid andCompletionHandle:(void (^)(U9InvestStockModel *, NSError *))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@&clubid=%@",uid,sessionid,cid];
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kCancelInvest]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9InvestStockModel *model = [U9InvestStockModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


+(void)getClubIncomeWithClubID:(NSString *)cid andUserid:(NSString *)uid andSessionid:(NSString *)sessionid andCompletionHandle:(void (^)(U9InvestStockModel *, NSError *))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@&clubid=%@",uid,sessionid,cid];
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetClubIncome]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9InvestStockModel *model = [U9InvestStockModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


@end
